package com.itheima.controller;

import com.itheima.pojo.BsUser;
import com.itheima.service.LoginService;
import com.itheima.util.PageResult;
import com.itheima.util.SimpleResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping
public class UserController {
    @Autowired
    private LoginService loginService;

    //根据id修改用户信息
    @PutMapping("/users/{id}")
    public void updateById(@PathVariable Integer id ,@RequestBody BsUser bsuser){
        bsuser.setId(id);
        loginService.UpdateUser(bsuser);
    }
    //2022-01-10  分页条件查询
    @GetMapping("/users")
    public PageResult findByPage(Integer page,Integer pagesize,String username){
        PageResult pageResult = loginService.findPage(page,pagesize,username);
        return pageResult;
    }
    //2022-01-10  用户删除
    @DeleteMapping("/users/{id}")
    public void delete(@PathVariable Integer id){
        loginService.deleteById(id);
    }
    //2022-01-10  用户禁用启用
    @PutMapping("/users/{id}/{disabled}")
    public void updateAbled(@PathVariable Integer id,@PathVariable boolean disabled){
        loginService.updateAbled(id,disabled);
    }
    //2022-01-10  用户添加
    @PostMapping("/users")
    public void add(@RequestBody BsUser bsUser){
        loginService.add(bsUser);
    }

    //根据id获得用户信息显示在修改页面
    @GetMapping("/users/{id}")
    public BsUser UpdateShow(@PathVariable Integer id){
        return loginService.UpdateShow(id);
    }
    //2022-01-10  用户重置密码用户重置密码
    @PutMapping("/users/{id}/password")
    public void updatepassword (@PathVariable Integer id,@RequestBody String password){
        System.out.println(password);
        loginService.updatepassword(id,password);
    }
}
